package com.socool.sinofaith.ui;

import com.deying.actionbarcompat.ActionBarHelperBase;
import com.deying.actionbarcompat.ActionBarHelperBase.CenterViewFactory;
import com.deying.actionbarcompat.ActionBarHelperBase.SpinnerViewFactory;
import com.socool.sinofaith.R;
import com.socool.sinofaith.adapter.SyncWorkAdapter;
import com.socool.sinofaith.adapter.VinnosAdapter;
import com.socool.sinofaith.model.SynTaskResponse.SynTaskBean.SynSubtaskBean;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TextView;

/**
 * 提交统计-列表-列表详情(this)
 * @author jiang
 *
 */
public class SyncWorkActivity extends BaseActivity
		implements CenterViewFactory, SpinnerViewFactory, View.OnClickListener {

	public static final String SYN_SUBTASK = SyncWorkActivity.class.getName() + "SYN_SUBTASK";
	private SynSubtaskBean synSubtask;

	ActionBarHelperBase mActionBarHelperBase;

	private TabHost tabHost;

	private ListView lv;
	VinnosAdapter adapter;

	private ListView lv2;
	SyncWorkAdapter adapter2;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_sync_work);

		if (getIntent() != null && getIntent().hasExtra(SYN_SUBTASK)) {
			synSubtask = getIntent().getParcelableExtra(SYN_SUBTASK);
		} else {
			finish();
		}

		mActionBarHelperBase = (ActionBarHelperBase) this.getActionBarHelper();
		mActionBarHelperBase.setmCenterViewFactory(this);
		mActionBarHelperBase.setmSpinnerViewFactory(this);

		initTabHost();
		initListView();
	}

	private void initListView() {
		lv = (ListView) findViewById(R.id.lv);
		adapter = new VinnosAdapter(this);
		adapter.replace(synSubtask.getUnsubmitvinnos());
		lv.setAdapter(adapter);

		lv2 = (ListView) findViewById(R.id.lv2);
		adapter2 = new SyncWorkAdapter(this);
		adapter2.replace(synSubtask.getWorks());
		lv2.setAdapter(adapter2);
	}

	private static final String tab1 = "未操作";
	private static final String tab2 = "提交情况";

	private void initTabHost() {
		tabHost = (TabHost) findViewById(android.R.id.tabhost);
		tabHost.setup();
		View view = getLayoutInflater().inflate(R.layout.layout_tabwidgetview, null);
		((TextView) view.findViewById(R.id.tvName)).setText(tab1);
		tabHost.addTab(tabHost.newTabSpec(tab1).setIndicator(view).setContent(R.id.tab1));

		view = getLayoutInflater().inflate(R.layout.layout_tabwidgetview, null);
		((TextView) view.findViewById(R.id.tvName)).setText(tab2);
		tabHost.addTab(tabHost.newTabSpec(tab2).setIndicator(view).setContent(R.id.tab2));
	}

	@Override
	public void onClick(View v) {
	}

	@Override
	public View createSpinnerView() {
		return new View(this);
	}

	@Override
	public View createView() {
		TextView tv = new TextView(this);
		tv.setText(synSubtask.getSubtaskname());
		tv.setTextColor(this.getResources().getColor(R.color.white));
		tv.setTextSize(20);
		return tv;
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater menuInflater = getMenuInflater();
		menuInflater.inflate(R.menu.common, menu);
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		if (item.getItemId() == R.id.home) {
			finish();
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
